package com.etc.usercenter.controller;



import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.etc.common.Code;
import com.etc.common.CodeMessage;
import com.etc.usercenter.dao.UserRepository;
import com.etc.usercenter.po.User;

/**
 * 
 * Filename:    AuthController.java  
 * Description:   Mock 注册操作 用于获取密码
 * Copyright:   Copyright (c) 2018-2019 All Rights Reserved.
 * Company:     chinasofti.com Inc.
 * @author:     mazheng 
 * @version:    1.0  
 * Create at:   2020年3月4日 下午7:16:55  
 *  
 * Modification History:  
 * Date         Author      Version     Description  
 * ------------------------------------------------------------------  
 * 2020年3月4日      mazheng      1.0         1.0 Version  
 *
 */
@RestController
@RequestMapping("/auth")
public class AuthController {

    @Autowired
    private UserRepository userRepository;

    @Autowired
    private BCryptPasswordEncoder bCryptPasswordEncoder;

    @RequestMapping("/register")
    public String registerUser(@RequestBody User user){
//        User user = new User();
//        user.setUsername(registerUser.get("username"));
        user.setPassword(bCryptPasswordEncoder.encode(user.getPassword()));
        user.setRole("ROLE_ADMIN");
        User save = userRepository.save(user);
        return save.toString();
    }
    
    @PostMapping("/checkRole")
    public CodeMessage checkRole(User user, HttpServletRequest req){
       
        return CodeMessage.success(Code.SUCESS, "有权限",  "");
    }
}
